<template>
  <el-card class="stat-card" :style="{ borderLeft: `4px solid ${color}` }">
    <div class="stat-content">
      <!-- 所有内容在一行显示 -->
      <div class="stat-icon">
        <i :class="icon" :style="{ color }"></i>
      </div>
      
      <div class="text-container">
        <div class="stat-title">{{ title }}</div>
        <div class="stat-value">
          {{ formattedValue }}
          <span class="stat-unit">{{ unit }}</span>
        </div>
      </div>
    </div>
  </el-card>
</template>

<script lang="ts">
import { Component, Vue, Prop } from 'vue-property-decorator';

@Component
export default class StatCard extends Vue {
  // 保持原有props不变
  @Prop({ required: true }) title!: string;
  @Prop({ required: true }) value!: number;
  @Prop({ required: true }) icon!: string;
  @Prop({ default: '#409EFF' }) color!: string;
  @Prop({ default: '' }) unit!: string;

  get formattedValue(): string {
    return this.value.toLocaleString();
  }
}
</script>

<style lang="scss" scoped>
.stat-card {
  ::v-deep .el-card__body {
    padding: 12px 15px;
    height: 100%;
  }

  .stat-content {
    display: flex;
    align-items: center;
    gap: 15px;
    height: 100%;

    .stat-icon {
      font-size: 28px;
      flex-shrink: 0;
      display: flex;
      align-items: center;
    }

    .text-container {
      flex: 1;
      min-width: 0; // 防止文本溢出
      
      .stat-title {
        color: #909399;
        font-size: 14px;
        line-height: 1.4;
        margin-bottom: 4px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }

      .stat-value {
        font-size: 22px;
        font-weight: bold;
        color: #303133;
        line-height: 1.2;
        display: flex;
        align-items: baseline;
        gap: 4px;

        .stat-unit {
          font-size: 12px;
          color: #909399;
          font-weight: normal;
          line-height: 1;
        }
      }
    }
  }
}
</style>